<?php
/**
 * Created by PhpStorm.
 * User: zq
 * Date: 2017/2/21
 * Time: 11:58
 */

namespace Admin\Controller;


use Common\Controller\AdminController;
use Common\Model\TypeModel;


class TypeController extends AdminController

{
    public function index(){
        $typeData = m('type')->select();
        $this->assign('typeData',$typeData);
        $this->display();
    }
    //类型添加
    public function add(){
        $id = I('get.tid');
        if(IS_POST){
//            dump($_POST);
            $data = I('post.');
            if($id){
                $data['tid'] =$id;
            }
//            dump($data);die;
            $this->store(new TypeModel(),$data,function(){
                $this->success('操作成功',u('index'));die;
            });
        }
        //分配旧数据
        if($id){
            $oldData = m('type')->find($id);
        }else{
            $oldData =[];
        }
        $this->assign('oldData', $oldData);
        $this->display();
    }
    //类型删除
    public function delType(){
        $tid =I('get.tid');
//        dump($tid);die;
        $model = new TypeModel();
        if($model->where("tid={$tid}")->delete()){
            $this->success('删除成功');
        }else{
            $this->error('删除失败');
        }
    }


}